home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / moreappleevents / morefinderevents.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  20.6 KB  |  676 lines

  1. /*
  2.     File:        MoreFinderEvents.c
  3.  
  4.     Contains:    Functions to help you build and sending Apple events to the Finder.
  5.  
  6.     Written by: Andy Bachorski    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. //    A private conditionals file to setup the build environment for this project.
  24.  
  25. #include "PrivateConditionals.h"
  26.  
  27.  
  28. //**********    Universal Headers        ****************************************
  29.  
  30. #include <Aliases.h>
  31. #include <ASRegistry.h>
  32. #include <Folders.h>
  33. #include <Icons.h>
  34. #include <OSA.h>
  35. #include <TextUtils.h>
  36.  
  37.  
  38. #if UNIVERSAL_INTERFACES_VERSION >= 0x0300
  39.     #include <AEDataModel.h>
  40.     #include <FinderRegistry.h>
  41. #else
  42.     #include "FinderRegistry.h"
  43. #endif
  44.  
  45.  
  46. //**********    Project Headers            ****************************************
  47.  
  48. #include "FinderRegistry.h"
  49. #include "AEHelpers.h"
  50. #include "ObjectHelpers.h"
  51. #include "MoreFinderEvents.h"
  52. #include "ProcessHelpers.h"
  53.  
  54.  
  55. //******************************************************************************
  56.  
  57. pascal OSErr MFESetSelectionToNone( const AEIdleUPP idleProcUPP )
  58. {
  59.     OSErr        anErr = noErr;
  60.     
  61.     AppleEvent    theEvent = { typeNull, nil };    //    If you always init AEDescs, it's always save to dispose of them.
  62.     
  63.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  64.                                               kAECoreSuite, kAESetData, &theEvent );
  65.     if ( anErr == noErr )
  66.     {
  67.         AEDesc        containerObj = { typeNull, nil };    // start with the null (application) container
  68.         AEDesc         propertyObject = { typeNull, nil };
  69.             
  70.         anErr = OHMakePropertyObject( pSelection, &containerObj, &propertyObject );
  71.         if ( anErr == noErr )
  72.         {
  73.             anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  74.             AEDisposeDesc( &propertyObject );    //    Always dispose of objects as soon as you are done (helps avoid leaks)
  75.             if ( anErr == noErr )
  76.             {
  77.                 AEDescList        emptyList = { typeNull, nil };
  78.                 
  79.                 anErr = AECreateList( nil, 0, false, &emptyList );
  80.                 if ( anErr == noErr )
  81.                 {
  82.                     anErr = AEPutParamDesc( &theEvent, keyAEData, &emptyList );
  83.                     if ( anErr == noErr )
  84.                     {
  85.                         anErr = AEHSendEventNoReturnValue( idleProcUPP, &theEvent );
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  91.     }
  92.     return anErr;
  93. } // MFESetSelectionToNone
  94.  
  95. //******************************************************************************
  96.  
  97. pascal OSErr MFEChangeFolderViewNewSuite( const FSSpecPtr fssPtr,
  98.                                           const long viewStyle,
  99.                                           const AEIdleUPP idleProcUPP )
  100. {
  101.     OSErr        anErr = noErr;
  102.     
  103.     AppleEvent    theEvent = {typeNull, nil};
  104.     
  105.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  106.                                               kAECoreSuite, kAESetData, &theEvent );
  107.     if ( anErr == noErr )
  108.     {
  109.         AEDesc         folderObject = {typeNull, nil};
  110.         AEDesc        containerObj = { typeNull, nil };    // start with the null (application) container
  111.         
  112.         anErr = OHMakeAliasObjectFromFSSpec( fssPtr, &containerObj, &folderObject );
  113.         if ( anErr == noErr )
  114.         {
  115.             AEDesc         propertyObject = {typeNull, nil};
  116.             
  117.             anErr = OHMakePropertyObject( pView, &folderObject, &propertyObject );
  118.             AEDisposeDesc( &folderObject );
  119.             if ( anErr == noErr )
  120.             {
  121.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  122.                 AEDisposeDesc( &propertyObject );
  123.                 if ( anErr == noErr )
  124.                 {
  125.                     anErr = AEPutParamPtr( &theEvent, keyAEData,
  126.                                            typeLongInteger, &viewStyle, sizeof(viewStyle) );
  127.                     if ( anErr == noErr )
  128.                     {
  129.                         anErr = AEHSendEventNoReturnValue( idleProcUPP, &theEvent );
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  135.     }
  136.     return anErr;
  137. } // MFEChangeFolderView
  138.  
  139. //******************************************************************************
  140.  
  141. pascal OSErr MFEChangeFolderViewOldSuite( const FSSpecPtr fssPtr,
  142.                                           const long viewStyle,
  143.                                           const AEIdleUPP idleProcUPP )
  144. {
  145.     OSErr        anErr = noErr;
  146.     
  147.     AppleEvent    theEvent = {typeNull, nil};
  148.     
  149.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  150.                                               kAEFinderEvents, kAEChangeView, &theEvent );
  151.     if ( anErr == noErr )
  152.     {
  153.         anErr = OHAddAliasParameterFromFSS( fssPtr, keyDirectObject, &theEvent );
  154.         if ( anErr == noErr )
  155.         {
  156.             anErr = AEPutParamPtr( &theEvent, keyMiscellaneous,
  157.                                    typeLongInteger, &viewStyle, sizeof( viewStyle ) );
  158.             if ( anErr == noErr )
  159.             {
  160.                 anErr = AEHSendEventNoReturnValue( idleProcUPP, &theEvent );
  161.             }
  162.         }
  163.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  164.     }
  165.     return anErr;
  166. } // MFEChangeFolderViewOldSuite
  167.  
  168. //******************************************************************************
  169.  
  170. pascal OSErr MFEChangeFolderView( const FSSpecPtr fssPtr,
  171.                                   const long viewStyle,
  172.                                   const AEIdleUPP idleProcUPP )
  173. {
  174.     OSErr    anErr = noErr;
  175.     
  176.     if ( FinderCallsAEProcess() )
  177.     {
  178.         if ( FinderIsOSLCompliant() )
  179.         {
  180.             anErr = MFEChangeFolderViewNewSuite( fssPtr, viewStyle, idleProcUPP );
  181.         }
  182.         else
  183.         {
  184.             anErr = MFEChangeFolderViewOldSuite( fssPtr, viewStyle, idleProcUPP );
  185.         }
  186.     }
  187.     else
  188.     {
  189.         anErr = errAEEventNotHandled;
  190.     }
  191.     
  192.     return anErr;
  193. }//end MFEChangeFolderView
  194.  
  195. //******************************************************************************
  196.  
  197. pascal OSErr MFEAddCustomIconToItem( const FSSpecPtr fssPtr,
  198.                                      const Handle theIconSuite,
  199.                                      const IconSelectorValue iconSelector,
  200.                                      const AEIdleUPP idleProcUPP )
  201. {
  202.     OSErr        anErr = noErr;
  203.     
  204.     AppleEvent    theEvent = {typeNull, nil};
  205.     
  206.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  207.                                               kAECoreSuite, kAESetData, &theEvent );
  208.     if ( anErr == noErr )
  209.     {
  210.         AEDesc         itemObject = {typeNull, nil};
  211.         AEDesc        containerObj = { typeNull, nil };        // start with the null (application) container
  212.         
  213.         anErr = OHMakeAliasObjectFromFSSpec( fssPtr, &containerObj, &itemObject );
  214.         if ( anErr == noErr )
  215.         {
  216.             AEDesc         propertyObject = {typeNull, nil};
  217.             
  218.             anErr = OHMakePropertyObject( pIconBitmap, &itemObject, &propertyObject );
  219.             AEDisposeDesc( &itemObject );
  220.             if ( anErr == noErr )
  221.             {
  222.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  223.                 AEDisposeDesc( &propertyObject );
  224.                 if ( anErr == noErr )
  225.                 {
  226.                     AEDescList    iconFamilyRec = { typeNull, nil };
  227.                     
  228.                     anErr = OHMakeIconFamilyRecord( theIconSuite, iconSelector, &iconFamilyRec );
  229.                     if ( anErr == noErr )
  230.                     {
  231.                         anErr = AEPutParamDesc( &theEvent, keyAEData, &iconFamilyRec );
  232.                         if ( anErr == noErr )
  233.                         {
  234.                             anErr = AEHSendEventNoReturnValue( idleProcUPP, &theEvent );
  235.                         }
  236.                     }
  237.                 }
  238.             }
  239.         }
  240.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  241.     }
  242.     return anErr;
  243. } // MFEAddCustomIconToItem
  244.  
  245. //******************************************************************************
  246.  
  247. pascal OSErr MFEGetItemIconSuite( const FSSpecPtr fssPtr,
  248.                                   const AEIdleUPP idleProcUPP,
  249.                                         Handle     *theIconSuite )
  250. {
  251.     OSErr    anErr = noErr;
  252.     
  253.     AppleEvent    theEvent = {typeNull, nil};
  254.     
  255.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  256.                                               kAECoreSuite, kAEGetData, &theEvent );
  257.     if ( anErr == noErr )
  258.     {
  259.         AEDesc         itemObject = {typeNull, nil};
  260.         AEDesc        containerObj = { typeNull, nil };        // start with the null (application) container
  261.         
  262.         anErr = OHMakeAliasObjectFromFSSpec( fssPtr, &containerObj, &itemObject );
  263.         if ( anErr == noErr )
  264.         {
  265.             AEDesc         propertyObject = {typeNull, nil};
  266.             
  267.             anErr = OHMakePropertyObject( pIconBitmap, &itemObject, &propertyObject );
  268.             AEDisposeDesc( &itemObject );
  269.             if ( anErr == noErr )
  270.             {
  271.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  272.                 AEDisposeDesc( &propertyObject );
  273.                 if ( anErr == noErr )
  274.                 {
  275.                     AppleEvent    theReply = {typeNull, nil};
  276.                     AESendMode    sendMode;
  277.                     
  278.                     if ( idleProcUPP == nil )
  279.                         sendMode = kAENoReply;
  280.                     else
  281.                         sendMode = kAEWaitReply;
  282.  
  283.                     anErr = AESend( &theEvent, &theReply, sendMode, kAENormalPriority,
  284.                                     kNoTimeOut, idleProcUPP, nil );
  285.                     if ( anErr == noErr )
  286.                     {
  287.                         anErr =  AEHGetHandlerError( &theReply );
  288.                         if ( anErr == noErr )
  289.                         {
  290.                             AEDesc    iconFamilyRec = { typeNull, nil };
  291.                             
  292.                             anErr = AEGetParamDesc( &theReply, keyDirectObject, typeWildCard, &iconFamilyRec );
  293.                             if ( anErr == noErr )
  294.                             {
  295.                                 anErr = OHMakeIconSuite( &iconFamilyRec, theIconSuite );
  296.                             }
  297.                             AEDisposeDesc( &iconFamilyRec );
  298.                         }
  299.                         AEDisposeDesc( &theReply );
  300.                     }
  301.                 }
  302.             }
  303.         }
  304.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  305.     }
  306.     return anErr;
  307. } // MFEGetItemIconSuite
  308.  
  309. //******************************************************************************
  310.  
  311. pascal OSErr MFEGetEveryItemOnDesktop( const AEIdleUPP idleProcUPP,
  312.                                              AEDescList *objectList )
  313. {
  314.     OSErr        anErr = noErr;
  315.     
  316.     AppleEvent    theEvent = {typeNull, nil};
  317.     
  318.     objectList->descriptorType = typeNull;
  319.     objectList->dataHandle = nil;
  320.     
  321.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  322.                                               kAECoreSuite, kAEGetData, &theEvent );
  323.     if ( anErr == noErr )
  324.     {
  325.         AEDesc        containerObj = { typeNull, nil };        // start with the null (application) container
  326.         AEDesc         propertyObject = {typeNull, nil};
  327.         
  328.         anErr = OHMakePropertyObject( kDesktopFolderType, &containerObj, &propertyObject );
  329.         if ( anErr == noErr )
  330.         {
  331.             DescType    selectAll = kAEAll;
  332.             AEDesc        allObjectsDesc = { typeNull, nil };
  333.             
  334.             anErr = OHMakeSelectionObject( selectAll, &propertyObject, &allObjectsDesc );
  335.             AEDisposeDesc( &propertyObject );
  336.             if ( anErr == noErr )
  337.             {
  338.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &allObjectsDesc );
  339.                 AEDisposeDesc( &allObjectsDesc );
  340.                 if ( anErr == noErr )
  341.                 {
  342.                     AppleEvent    theReply = {typeNull, nil};
  343.                     AESendMode    sendMode;
  344.                     
  345.                     if ( idleProcUPP == nil )
  346.                         sendMode = kAENoReply;
  347.                     else
  348.                         sendMode = kAEWaitReply;
  349.  
  350.                     anErr = AESend( &theEvent, &theReply, sendMode, kAENormalPriority,
  351.                                     kNoTimeOut, idleProcUPP, nil );
  352.                     if ( anErr == noErr )
  353.                     {
  354.                         anErr =  AEHGetHandlerError( &theReply );
  355.                         
  356.                         if ( !anErr && theReply.descriptorType != typeNull )
  357.                         {
  358.                             anErr = AEGetParamDesc( &theReply, keyDirectObject, typeAEList, objectList );
  359.                         }
  360.                         AEDisposeDesc( &theReply );
  361.                     }
  362.                 }
  363.             }
  364.         }
  365.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  366.     }
  367.     return anErr;
  368. } // MFEGetEveryItemOnDesktop
  369.  
  370. //******************************************************************************
  371.  
  372. pascal OSErr MFEGetViewFontAndSize( const AEIdleUPP idleProcUPP,
  373.                                           SInt16 *font,
  374.                                           SInt16 *fontSize )
  375. {
  376.     OSErr        anErr = noErr;
  377.     
  378.     AppleEvent    theEvent = {typeNull, nil};
  379.         
  380.     if ( idleProcUPP == nil )
  381.     {
  382.         return paramErr;
  383.     }
  384.     //    Build the event we will send
  385.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  386.                                               kAECoreSuite, kAEGetData, &theEvent );
  387.     if ( anErr == noErr )
  388.     {
  389.         AEDesc        containerObj = { typeNull, nil };        // start with the null (application) container
  390.         AEDesc         viewPropertyObj = {typeNull, nil};
  391.         //    Create an object descriptor for the view preferences property
  392.         anErr = OHMakePropertyObject( pViewPreferences, &containerObj, &viewPropertyObj );
  393.         if ( anErr == noErr )
  394.         {
  395.             AEDesc         fontPropertyObj = {typeNull, nil};
  396.             
  397.             //    Create an object descriptor for the view font property of the view preferences property
  398.             anErr = OHMakePropertyObject( pViewFont, &viewPropertyObj, &fontPropertyObj );
  399.             //    Don't dispose of the fontPropertyObj yet, we will need it for the font size property
  400.             if ( anErr == noErr )
  401.             {
  402.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &fontPropertyObj );
  403.                 (void) AEDisposeDesc( &fontPropertyObj );
  404.                 if ( anErr == noErr )
  405.                 {
  406.                     anErr = AEHSendEventReturnSInt16( idleProcUPP, &theEvent, font );
  407.                     if ( anErr == noErr )
  408.                     {
  409.                         AEDesc         fontSizePropertyObj = {typeNull, nil};
  410.                         
  411.                         anErr = OHMakePropertyObject( pViewFontSize, &viewPropertyObj, &fontSizePropertyObj );
  412.                         (void) AEDisposeDesc( &viewPropertyObj );    // always dispose of AEDescs when you are finished with them
  413.                         if ( anErr == noErr )
  414.                         {
  415.                             anErr = AEPutParamDesc( &theEvent, keyDirectObject, &fontSizePropertyObj );
  416.                             (void) AEDisposeDesc( &fontSizePropertyObj );
  417.                             if ( anErr == noErr )
  418.                             {
  419.                                 anErr = AEHSendEventReturnSInt16( idleProcUPP, &theEvent, fontSize );
  420.                             }
  421.                         }
  422.                     }
  423.                 }
  424.             }
  425.         }
  426.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  427.     }
  428.     return anErr;
  429. } // MFEGetEveryItemOnDesktop
  430.  
  431. //******************************************************************************
  432.  
  433. pascal OSErr MFEUpdateItemFSS( const FSSpecPtr fssPtr )
  434. {
  435.     OSErr            anErr = noErr;
  436.     AliasHandle        aliasHandle;
  437.     
  438.     anErr = NewAlias( nil, fssPtr, &aliasHandle);
  439.  
  440.     if ( anErr == noErr )
  441.     {
  442.         anErr = MFEUpdateItemAlias( aliasHandle );
  443.     }
  444.     
  445.     DisposeHandle( (Handle)aliasHandle );
  446.     
  447.     return anErr;
  448. } // MFEChangeFolderView
  449.  
  450. //******************************************************************************
  451.  
  452. pascal OSErr MFEUpdateItemAlias( const AliasHandle aliasHandle )
  453. {
  454.     OSErr        anErr = noErr;
  455.     
  456.     AppleEvent    theEvent = {typeNull, nil};
  457.     
  458.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  459.                                               kAEFinderSuite, kAEUpdate, &theEvent );
  460.     if ( anErr == noErr )
  461.     {
  462.         AEDesc         aliasDesc = {typeNull, nil};
  463.         
  464.         anErr = OHMakeAliasDesc( aliasHandle, &aliasDesc );
  465.         if ( anErr == noErr )
  466.         {
  467.             anErr = AEPutParamDesc( &theEvent, keyDirectObject, &aliasDesc );
  468.             AEDisposeDesc( &aliasDesc );
  469.             if ( anErr == noErr )
  470.             {
  471.                 anErr = AEHSendEventNoReturnValue( nil, &theEvent );
  472.             }
  473.         }
  474.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  475.     }
  476.     return anErr;
  477. } // MFEUpdateItemAlias
  478.  
  479. //******************************************************************************
  480.  
  481. pascal OSErr MFESetProcessVisibility( const ProcessSerialNumberPtr psnPtr, Boolean visible )
  482. {
  483.     OSErr        anErr = noErr;
  484.     AppleEvent    theEvent = { typeNull, nil };
  485.     
  486.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  487.                                               kAECoreSuite, kAESetData, &theEvent );
  488.     if ( anErr == noErr )
  489.     {
  490.         OSType        processType;
  491.         OSType        processSignature;
  492.         
  493.         anErr = GetProcessTypeSignature( psnPtr, &processType, &processSignature );
  494.         if ( anErr == noErr )
  495.         {
  496.             AEDesc     processObject = { typeNull, nil };
  497.             
  498.         //    To hide the Finder it's visible property is directly set to false -- no process target
  499.         //    is needed.  Only create a non-null processObject if the Finder is not the target.
  500.             if ( (processSignature != kFinderProcessSignature)  ||  (processType != kFinderProcessType) )
  501.             {    
  502.                 Str32    processName;
  503.                 
  504.             //    The Finder expects the process to be specified by name.
  505.                 anErr = GetProcessName( psnPtr, processName );
  506.                 if ( anErr == noErr )
  507.                 {
  508.                     AEDesc    containerObj = { typeNull, nil };
  509.                     AEDesc    nameDesc = { typeNull, nil };
  510.                     
  511.                     anErr = AECreateDesc( typeChar, &processName[ 1 ], processName[ 0 ], &nameDesc );
  512.                     if ( anErr == noErr )
  513.                     {
  514.                         anErr = CreateObjSpecifier( cProcess, &containerObj, formName,
  515.                                                     &nameDesc, false, &processObject );
  516.                         (void) AEDisposeDesc( &nameDesc );
  517.                     }
  518.                 }
  519.             }
  520.             
  521.             if ( anErr == noErr )
  522.             {
  523.                 AEDesc    propertyObject = { typeNull, nil };
  524.  
  525.             //    To hide a process tell the Finder to set the process' visible property to false.
  526.                 anErr = OHMakePropertyObject( pVisible, &processObject, &propertyObject );
  527.                 (void) AEDisposeDesc( &processObject );
  528.                 if ( anErr == noErr )
  529.                 {
  530.                     anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  531.                     (void) AEDisposeDesc( &propertyObject );
  532.                     if ( anErr == noErr )
  533.                     {
  534.                         anErr = AEPutParamPtr( &theEvent, keyAEData, typeBoolean, &visible, sizeof(Boolean) );
  535.                         if ( anErr == noErr )
  536.                         {
  537.                             anErr = AEHSendEventNoReturnValue( nil, &theEvent );
  538.                         }
  539.                     }
  540.                 }
  541.             }
  542.         }
  543.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  544.     }
  545.     return anErr;
  546. } // MFEChangeFolderView
  547.  
  548. //******************************************************************************
  549.  
  550. pascal    OSErr MFEOpenFile( const FSSpec *fssPtr )
  551. {
  552.     OSErr        anErr = noErr;
  553.     
  554.     AppleEvent    theEvent = { typeNull, nil };
  555.     
  556.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  557.                                               kAECoreSuite, kAEOpen, &theEvent );
  558.     if ( anErr == noErr )
  559.     {
  560.         anErr = AEPutParamPtr( &theEvent, keyDirectObject, typeFSS, fssPtr, sizeof( FSSpec ) );
  561.         if ( anErr == noErr )
  562.         {    
  563.             anErr = AEHSendEventNoReturnValue( nil, &theEvent );
  564.         }
  565.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  566.     }
  567.     return anErr;
  568. }//end MFEOpenFile
  569.  
  570. //******************************************************************************
  571.  
  572. pascal    OSErr    MFEMakeAliasFile( const FSSpecPtr sourceFSSPtr,
  573.                                   const FSSpecPtr destFSSPtr,
  574.                                   ConstStr63Param newName,
  575.                                   const AEIdleUPP idleProcUPP )
  576. {
  577.     OSErr        anErr = noErr;
  578.     
  579.     AppleEvent    theEvent = { typeNull, nil };
  580.     
  581.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  582.                                               kAECoreSuite, kAECreateElement, &theEvent );
  583.     if ( anErr == noErr)
  584.     {
  585.         //    put the type of item to make into the Apple event
  586.         OSType    anAliasType = typeAlias;
  587.         
  588.         anErr = AEPutParamPtr( &theEvent, keyAEObjectClass, typeType, &anAliasType, sizeof(OSType));
  589.         if ( anErr == noErr)
  590.         {
  591.             //    add an alias that points to the targer for the alias file to be created
  592.             anErr = OHAddAliasParameterFromFSS( sourceFSSPtr, keyASPrepositionTo, &theEvent );
  593.             if ( anErr == noErr)
  594.             {
  595.                 //    where should the alias file be created?
  596.                 anErr = OHAddAliasParameterFromFSS( destFSSPtr, keyAEInsertHere, &theEvent );
  597.                 if ( anErr == noErr)
  598.                 {
  599.                     //    add a properties record so we can specify the name of the new alias file.
  600.                     AERecord    properties = { typeNull, nil };
  601.                     
  602.                     anErr = AECreateList( nil, 0, true, &properties );
  603.                     if ( anErr == noErr)
  604.                     {
  605.                         anErr = AEPutKeyPtr( &properties, keyAEName, typeChar, newName+1, *newName );
  606.                         if ( anErr == noErr)
  607.                         {
  608.                             anErr = AEPutParamDesc( &theEvent, keyAEPropData, &properties );
  609.                             if ( anErr == noErr)
  610.                             {
  611.                                 //    Send the event. In this case we don't care about the reply, but if we did we
  612.                                 //    would get back an object that describes the alias file just created
  613.                                 //    ( either an object descriptor, an alias, or an FSSpec, depending on what we ask for).
  614.                                 anErr = AEHSendEventNoReturnValue( idleProcUPP, &theEvent );
  615.                             }
  616.                         }
  617.                         AEDisposeDesc( &properties );
  618.                     }
  619.                 }
  620.             }
  621.         }
  622.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  623.     }
  624.     return anErr;
  625. }//end MFEMakeAliasFile
  626.  
  627. //******************************************************************************
  628.  
  629. pascal OSErr MFEMoveDiskIcon( const FSSpecPtr fssPtr,
  630.                               const Point position )
  631. {
  632.     OSErr        anErr = noErr;
  633.     
  634.     AppleEvent    theEvent = {typeNull, nil};
  635.     
  636.     anErr = AEHMakeEventSignatureTarget( kFinderFileType, kFinderCreatorType,
  637.                                               kAECoreSuite, kAESetData, &theEvent );
  638.     if ( anErr == noErr )
  639.     {
  640.         AEDesc         itemObject = {typeNull, nil};
  641.         AEDesc        containerObj = { typeNull, nil };    // start with the null (application) container
  642.         
  643.         anErr = OHMakeAliasObjectFromFSSpec( fssPtr, &containerObj, &itemObject );
  644.         if ( anErr == noErr )
  645.         {
  646.             AEDesc         propertyObject = {typeNull, nil};
  647.             
  648.             anErr = OHMakePropertyObject( pPosition, &itemObject, &propertyObject );
  649.             AEDisposeDesc( &itemObject );
  650.             if ( anErr == noErr )
  651.             {
  652.                 anErr = AEPutParamDesc( &theEvent, keyDirectObject, &propertyObject );
  653.                 AEDisposeDesc( &propertyObject );
  654.                 if ( anErr == noErr )
  655.                 {
  656.                     AEDescList    posList;
  657.                     
  658.                     anErr = OHMakePositionList( position, &posList );
  659.                     if ( anErr == noErr )
  660.                     {
  661.                         anErr = AEPutParamDesc( &theEvent, keyAEData, &posList );
  662.                         if ( anErr == noErr )
  663.                         {    
  664.                             anErr = AEHSendEventNoReturnValue( nil, &theEvent );
  665.                         }
  666.                     }
  667.                 }
  668.             }
  669.         }
  670.         (void) AEDisposeDesc( &theEvent );    // always dispose of AEDescs when you are finished with them
  671.     }
  672.     return anErr;
  673. } // MFEChangeFolderView
  674.  
  675. //******************************************************************************
  676.